#include("../../comm/ListHead.html")
<style>
</style>
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md2 height-auto width-14">
            <div class="layui-card height-scoll">
                <div id="tree_1" class="demo-tree demo-tree-box"></div>
            </div>
        </div>
        <div class="layui-col-md10 width-86">
            <div class="layui-card">
                <div class="card-search SearchTable">
                    <p style="float:right">
                        <input type="hidden" id="p_id" name="p_id" value="#(form.data.def_id??)"/>
                        <input type="hidden" id="titles" name="titles" value="#(form.data.def_title??)"/>
                        <input type="text" id="test_id" placeholder="测试ID" class="table-search-text width80"/>
                        <input type="text" id="test_name" placeholder="测试名称" class="table-search-text width80"/>

                        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="DoSearch">
                            搜索
                        </button>
                        <button class="layui-btn btn-search-adv layui-btn-sm" lay-event="DoSearchMore">高级搜索</button>

                    </p>
                    当前页面：<span id="navtitle" class="color_green">[#(form.data.def_id??)]#(form.data.def_title??)</span>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="table_1_bar_title">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="AddTestDemo">
                                <i class="layui-icon">&#xe608;</i> 添加开发测试
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="EditTestDemo">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="DelTestDemo">删除</button>
                        </div>
                    </script>
                    <script type="text/template" id="SearchMoreTemp">
                        <form class="layui-form">
                            <div class="margin-10"><input type="text" id="test_title" placeholder="请输入标题" autocomplete="off" class="layui-input"></div>
                            <div class="margin-10"><input type="text" id="test_url" placeholder="请输入测试路经" autocomplete="off" class="layui-input"></div>
                        </form>
                    </script>

                    <script type="text/html" id="temp_is_show">
                        <input type="checkbox" field="is_show" msg="显示" value="{{d.test_id}}" title="允许" lay-filter="ChangeTag" {{ d.is_show ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="temp_is_check">
                        <input type="checkbox" lay-skin="primary" field="is_check" msg="设置点击" value="{{d.test_id}}" lay-filter="ChangeTag" {{ d.is_check ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="temp_pub_tag">
                        <input type="checkbox" lay-skin="switch" field="pub_tag" msg="发布" value="{{d.test_id}}" lay-text="ON|OFF" lay-filter="ChangeTag" {{ d.pub_tag ? 'checked' : '' }}>
                    </script>
                    <script type="text/html" id="table_bar_tool">
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="EditTestDemo">修改</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">

    layui.use(['myTable', 'table', 'form', 'myTree', 'myTool', 'drawer'], function () {
        admin = layui.admin, myTool = layui.myTool, form = layui.form, myTree = layui.myTree;
        var $ = layui.$;
        treedata = #(form.data.tree);

        /**
         * 树渲染
         */
        myTree.render({
            data: treedata, init:  $("#p_id").val()
            , click: function (obj) {
                var data = obj.data;
                if (data.turn) {
                    $("#p_id").val(data.id);
                    $("#navtitle").html("[" + data.id + "]" + data.title);
                    $("#titles").val(data.title);
                    tableindex.reload({where: {p_id: data.id}, page: {curr: 1}});
                }
            }
        });

        drawer1 = layui.drawer.render({
            title: '<b><i class="layui-icon layui-icon-app"></i> 高级搜索</b>', offset: 'r', width: "300px", content: SearchMoreTemp.innerHTML,
            btn: ['<i class="layui-icon">&#xe615;</i>搜索', '重置'],
            success: function (layero, index) {
                layui.form.render('select');
            },
            btn1: function (index, layero) {
                tableindex.reload({
                    where: {
                        p_id: $("#p_id").val(), s: {
                            test_id: $(layero).find("#test_id").val()
                            , test_name: $(layero).find("#test_name").val()
                            , test_title: $("#test_title").val()
                            , test_url: $("#test_url").val()
                        }
                    }
                    , page: {curr: 1}
                });
            },
            btn2: function (index, layero) {
                $(layero).find("form")[0].reset();//重置
                return false;
            }
        });

        /**
         * 表格
         */
        tableindex = layui.myTable.render({
            elem: '#table_1', url: 'TestDemoListDataApi'
            , title: '列表'
            , where: {p_id: $("#p_id").val()}
            , cols: [[
                {type: 'checkbox', width: 36, fixed: true}
                , {field: 'p_id', title: '上级ID', width: 80, align: 'center'}
                , {field: 'test_color2', title: '色值', width: 80, align: 'center'}
                , {field: 'test_color', title: '色值', width: 80}
                , {field: 'test_icon2', title: '图标', width: 80}
                , {field: 'test_icon', title: '图标', width: 80}
                , {field: 'test_number2', title: '数字2', width: 80}
                , {field: 'test_number', title: '数字', width: 80}
                , {field: 'test_id', title: '测试ID', width: 80, sort: true}
                , {field: 'test_name', title: '测试名称', width: 120}
                , {field: 'test_title', title: '标题', width: 100}
                , {field: 'pub_date', title: '发布时间', width: 150}
                , {field: 'test_img', title: '图片', width: 80, align: 'center'}
                , {field: 'test_img2', title: '背景', width: 80, align: 'center'}
                , {field: 'sindex', title: '顺序', width: 80, edit: 'text', align: 'center'}
                , {field: 'is_show', title: '显示', width: 90, align: 'center', templet: '#temp_is_show'}
                , {field: 'is_check', title: '点击', width: 80, align: 'center', templet: '#temp_is_check'}
                , {field: 'pub_tag', title: '发布', width: 80, align: 'center', templet: '#temp_pub_tag'}
                , {field: 'test_desc', title: '备注'}
                , {title: '操作', toolbar: '#table_bar_tool', width: 60, align: 'center'}
            ]]
            , page: true, limit: 10
            , serviceSort: true, initSort: {field: 'test_id', type: 'desc'}
            , editField: {url: 'ModifyTestDemoFieldApi', key: 'test_id'}
        });

        /**
         * 按钮事件
         */
        layui.util.event("lay-event", {
            DoSearch: function () {
                tableindex.config.where = {p_id: $("#p_id").val(), s: {test_id: $("#test_id").val(), test_name: $("#test_name").val()}};
                tableindex.reload({where: tableindex.config.where, page: {curr: 1}});
            }
            , DoSearchMore: function () {
                layui.form.render();
                drawer1.open();
            }
        });

        /**
         * 工具栏事件
         */
        layui.table.on('toolbar(table_1)', function (obj) {
            myTool.toolbar(this, obj, {
                AddTestDemo: function () {
                    index = top.layer.open({
                        type: 2, offset: '60px', area: ['700px', '550px'], title: ['添加开发测试', 'font-size:15px;'],
                        content: ["testdemo/AddTestDemo?p_id=" + $("#p_id").val(), 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
                , EditTestDemo: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = top.layer.open({
                            type: 2, offset: '60px', area: ['700px', '550px'], title: ['修改开发测试[' + data[0].test_id + ']', 'font-size:15px;'],
                            content: ["testdemo/EditTestDemo?test_id=" + data[0].test_id, 'no'],
                            end: function () {
                                tableindex.reload({});
                            }
                        });
                    });
                }
                , DelTestDemo: function () {
                    myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                        index = layer.confirm('你是否确认删除开发测试【' + data[0].test_id + '】', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                            myTool.postMsg("DelTestDemoApi", {
                                test_id: data[0].test_id
                            }, function () {
                                layer.close(index2);
                                tableindex.reload();
                            });
                        });
                    });
                }
            });
        });

        /**
         * 工具栏事件
         */
        layui.table.on('tool(table_1)', function (obj) {
            myTool.tool(this, obj, {
                EditTestDemo: function (data) {
                    index = top.layer.open({
                        type: 2, offset: '60px', area: ['760px', '550px'], title: ['修改表[' + data.test_id + ']', 'font-size:15px;'],
                        content: ["testdemo/EditTestDemo?test_id=" + data.test_id, 'no'],
                        end: function () {
                            tableindex.reload({});
                        }
                    });
                }
            });
        });

        form.on('checkbox(ChangeTag)', function (obj) {
            myTool.postMsg("ChangeTestDemoTagApi", {key: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });
        form.on('switch(ChangeTag)', function (obj) {
            myTool.postMsg("ChangeTestDemoTagApi", {key: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
                layer.tips(result.msg, obj.othis);
            });
        });
    });
</script>
#include("../../comm/Foot.html")